using System;

namespace Parser
{
    /// <summary>
    /// Represents an exception that is used by the parser. It indicates the beginning
    /// and the end of incorrect characters in entered formula. 
    /// </summary>
    public class ParserException : Exception
    {
        private readonly int start;

        private readonly int end;

        /// <summary>
        /// Beginning character of the error.
        /// </summary>
        public int Start
        {
            get
            {
                return start;
            }
        }

        /// <summary>
        /// End character of the error.
        /// </summary>
        public int End
        {
            get
            {
                return end;
            }
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="N">Exception message</param>
        public ParserException(String N) : base(N)
        {
            start = 0;
            end	= 0;
        }

        /// <summary>
        /// Constructor that specifies the first and the last character of an error.
        /// </summary>
        /// <param name="a">Beginning index</param>
        /// <param name="b">End index</param>
        /// <param name="N">Exception message</param>
        public ParserException(int a,int b, String N) : base(N)
        {
            if ( a < 0 || b < 0 ) throw new Exception("error: Start and end cannot be negative");
            start = a;
            end	= b;
        }
    }
}